package com.nccsjz.back.bulletin.service;

import java.sql.SQLException;
import java.util.List;

import com.nccsjz.back.bulletin.dao.BulletinDAO;
import com.nccsjz.base.BaseService;
import com.nccsjz.pojo.Bulletin;
import com.nccsjz.utils.Pager;

public class BulletinService extends BaseService{
   //add bullet service
	public boolean addBulletin(Bulletin bulletin) throws SQLException{
		boolean flag=false;
		try{
		   openCon();
		   flag=new BulletinDAO(con).addBullet(bulletin);
		}finally{
			closeCon();
		}
		return flag;
	}
  //delete bulletin service
	public boolean deleteBulletin(Long id) throws SQLException{
		boolean flag=false;
		try{
			openCon();
			flag=new BulletinDAO(con).deleteBulletin(id);
		}finally{
			closeCon();
		}
		return flag;
	}
  //update bulletin service
	public boolean updateBulletin(Bulletin bulletin) throws SQLException{
		boolean flag=false;
		try{
			openCon();
			flag=new BulletinDAO(con).updateBulletin(bulletin);
		}finally{
			closeCon();
		}
		return flag;
	}
   //get one Bulletin 
	public Bulletin getBulletin(Long id) throws SQLException{
		Bulletin bulletin=null;
		try{
			openCon();
			bulletin=new BulletinDAO(con).getBulletin(id);
		}finally{
			closeCon();
		}
		return bulletin;
	}
	//batch deldete bulletin
	public boolean batchDeleteBulletin(List<Long> list) throws SQLException{
		boolean flag=false;
		try{
			openCon();
			con.setAutoCommit(false);
			flag=new BulletinDAO(con).deleteBathBulletin(list);
			con.commit();
			
		}finally{
			closeCon();
		}
		return flag;
	}
	//page display bulletin
	public Pager getBulletin(int pageSize,int pageNo) throws SQLException{
		Pager pager=null;
		try{
			openCon();
			pager=new BulletinDAO(con).getBulletin(pageSize, pageNo);
		}finally{
			closeCon();
		}
		return pager;
	}
	/**
	 * 最新 公告.
	 * @return
	 * @throws Exception 
	 */
	public Bulletin getLastBulletin() throws Exception{
		Bulletin b=new Bulletin();
		this.openCon();
		b=new BulletinDAO(con).getLastBulletin();
		this.closeCon();
		return b; 
	}
}
